FROM alpine:3.16

ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file tar zip g++ gcc libstdc++ libc-dev make pkgconf re2c pcre-dev pcre2-dev libtool automake"

COPY ./run.sh /run.sh
COPY ./init.sh /init.sh

#RUN apk update && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS

RUN set -ex \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update \
  	&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
    && apk add --no-cache openssl \
    curl \
    bash \
    zlib-dev \
    ca-certificates \
    libaio-dev \
    openssl-dev \
    curl-dev \
    tzdata \
    # 安装php
    php8 \
    php8-pear \
    php8-dev \
    php8-mysqli \
    php8-pdo_mysql \
    php8-pdo_sqlite \
    php8-mbstring \
    php8-json \
    php8-zlib \
    php8-gd \
    php8-intl \
    php8-session \
    php8-fpm \
    php8-curl \
    php8-gmp \
    php8-posix \
    php8-fileinfo \
    php8-simplexml \
    php8-opcache  \
    php8-sodium \
    php8-tokenizer \
    php8-ctype \
    php8-bcmath \
    php8-openssl \
    php8-dom \
    php8-iconv \
    php8-sockets \
    php8-zip \
    php8-pcntl \
    php8-xmlwriter \
    php8-xmlreader \
    php8-redis \
    php8-xml \
    php8-phar \
    php8-pecl-event \
    #php8-pecl-xlswriter \
    && cp "/usr/share/zoneinfo/Asia/Shanghai" /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && update-ca-certificates \
    #添加 www用户组和用户
    && addgroup -g 1000 www \
    && adduser -u 1000 -D -S -G www www \
    && mkdir /www  \
    && chown www:www /www \
    && chmod 1777 /www \
    && ln -s /usr/sbin/php-fpm8 /usr/sbin/php-fpm \
    && chmod +x /run.sh \
    && chmod +x /init.sh \
    && sh /init.sh \
    && wget https://mirrors.tencent.com/composer/composer.phar \
    && mv composer.phar  /usr/local/bin/composer \
    && chmod 755 /usr/local/bin/composer \
     # ---------- clear works ----------
    #&& apk del .build-deps \
    && apk del tzdata \
    #&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && composer config -g repos.packagist composer https://mirrors.huaweicloud.com/repository/php/

ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /www

EXPOSE 9000

CMD ["/run.sh"]